package com.health.demo.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.health.demo.common.vo.Result;
import com.health.demo.common.vo.Search;
import com.health.demo.entity.Drug;
import com.health.demo.service.DrugService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 洛璃依
 * @since 2022-12-07 01:57:02
 */
@RestController
@RequestMapping("/api/drugManager")
public class DrugController {

    @Autowired
    DrugService drugService;

    @PostMapping(value = "/drug/add",consumes = "application/json")
    public Result<Drug> addDrug(@RequestBody Drug drug){
        return drugService.addDrug(drug);
    }

    @DeleteMapping(value = "/drug/{drugId}",consumes = "application/json")
    public Result<Drug> delDrug(@PathVariable Integer drugId){
        return drugService.deleteDrug(drugId);
    }

    @PostMapping(value = "/drug/update",consumes = "application/json")
    public Result<Drug> updateDrug(@RequestBody Drug drug){
        return drugService.updateDrug(drug);
    }

    @GetMapping(value = "/drug/{drugId}")
    public Drug selectDrugById(@PathVariable Integer drugId){
        return drugService.selectDrugById(drugId);
    }

    @PostMapping(value = "/drugs",consumes = "application/json")
    public Page<Drug> selectDrugPage(@RequestBody Search search){
        return drugService.selectDrugPage(search);
    }
}

